package com.tanhua.server.controller;

import com.tanhua.commons.exception.TanHuaException;
import com.tanhua.domain.vo.QueryVoiceVo;
import com.tanhua.server.service.VoiceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Slf4j
@RestController
@RequestMapping("/peachblossom")
public class VoiceController {

    @Autowired
    private VoiceService voiceService;

    /**
     * 保存语音
     *
     * @param soundFile
     * @return
     */
    @PostMapping
    public ResponseEntity saveVoice(@RequestBody MultipartFile soundFile) {

        voiceService.saveVoice(soundFile);
        return ResponseEntity.ok(null);
    }

    /**
     * 查询推荐语音
     *
     * @return
     */
    @GetMapping
    public ResponseEntity findVoice() {
        QueryVoiceVo queryVoiceVo = voiceService.queryVoice();
        if (queryVoiceVo == null) throw new TanHuaException("暂无推荐语音，请过会儿再来~");
        return ResponseEntity.ok(queryVoiceVo);
    }
}
